function jsLoader(mod)
{
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");
}

function showBannerDir(type)
{
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");
	$.ajax({
        type: "POST",
        data: ({mediatype: type}),
        url: "/admin/content/showbanner/",
        success: function(data){
            $("#loader").hide();
            $("#dataviewer").html(data);            
        }
    });
}

function deleteImage(imgpath)
{
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");
	$.ajax({
        type: "POST",
        data: ({imgpath: imgpath}),
        url: "/admin/content/delimage/",
        success: function(data){
            $("#loader").hide();
            $("#msgbox").html(data);
            location.href='/admin/content/media/STAT/del';
        }
    });
}

function editPromoBanner(banner_id)
{
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");
	$.ajax({
        type: "POST",
        data: ({banner_id: banner_id}),
        url: "/admin/content/changeimage/",
        success: function(data){
            $("#loader").hide();                               
            data_arr = data.split("|");
            $("#txtBannerId").val(data_arr[0]);
            $("#txtBannerTitle").val(data_arr[1]);
            $("#txtBannerDesc").val(data_arr[2]);
            $("#txtBannerURL").val(data_arr[3]);            
            if(data_arr[4] == 1)
            {
            	$("#txtIsActive").attr('checked','checked');      
            } else {
            	$("#txtIsActive").attr('checked','');   
            }
            
            $("#txtBannerImg").val(data_arr[5]);
            $("#btnUpload").val("Update Banner");
        }
    });
}

function submitbutton(task)
{
    switch(task)
    {
      case 'article.cancel':
      location.href='/admin/blog/index/';
      break;

       case 'blog.add':
      location.href='/admin/blog/add/';
      break;

    }
}

function changeBannerStatus(banner_id)
{
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");
	
	$.ajax({
        type: "POST",
        data: ({banner_id: banner_id}),
        url: "/admin/content/changestatus/",
        success: function(data){
            $("#loader").hide();
            window.location.reload();
        }
    });
}

function savenews()
{
	var newsform = document.getElementById("newsform");
	newsform.submit();
}

function updatenews()
{
	var newsform = document.getElementById("newsform");
	newsform.submit();
}

function changeNewsStatus(news_id)
{
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");
	
	$.ajax({
        type: "POST",
        data: ({news_id: news_id}),
        url: "/admin/news/changestatus/",
        success: function(data){
            $("#loader").hide();
            window.location.reload();
        }
    });
}

function deleteNews(news_id)
{
	var msg = window.confirm("Are you sure you want to delete this record?");
	
	if(msg) {
		$("#loader").show();
		$("#loader").html("<img src='/images/loader.gif' /> loading...");
		
		$.ajax({
	        type: "POST",
	        data: ({news_id: news_id}),
	        url: "/admin/news/delete/",
	        success: function(data){
	            $("#loader").hide();
	            location.href = '/admin/news/index/stat/deleted/';	
	        }
	    });
	} else {
		return false;
	}
}

function addDefaultNewsContent()
{
	var news_title = $("#news_title");
	var oEditor = FCKeditorAPI.GetInstance('news_desc');

	if(news_title.val() == "")
	{
		alert("Main title is required and cannot be blank");
		news_title.focus();
		return false;
	} else if(!oEditor.GetXHTML(true)) {
		alert("Main description is required and cannot be blank");
		//news_title.focus();
		return false;
	} else {
		$.ajax({
	        type: "POST",
	        data: ({news_title: news_title.val(), news_desc: oEditor.GetXHTML(true)}),
	        url: "/admin/news/defaultdata/",
	        success: function(data){
	            $("#loader").hide();
	            location.href = '/admin/news/index/stat/updated/';	
	        }
	    });
	}
}

function updateDefaultNewsContent()
{
	var news_title = $("#news_title");
	var oEditor = FCKeditorAPI.GetInstance('news_desc');

	if(news_title.val() == "")
	{
		alert("Main title is required and cannot be blank");
		news_title.focus();
		return false;
	} else if(!oEditor.GetXHTML(true)) {
		alert("Main description is required and cannot be blank");
		//news_title.focus();
		return false;
	} else {
		$.ajax({
	        type: "POST",
	        data: ({news_title: news_title.val(), news_desc: oEditor.GetXHTML(true)}),
	        url: "/admin/news/updatedefaultdata/",
	        success: function(data){
	            $("#loader").hide();
	            location.href = '/admin/news/index/stat/updated/';	
	        }
	    });
	}
}

function savetabcontent()
{
	var homecontentform = document.getElementById("homecontentform");
	homecontentform.submit();
}

function deleteHomeContent(id)
{
    if(confirm("Are you sure that you want to delete this post?"))
        {
             location.href="/admin/homepage/delete/id/"+id;
        }
        else{
            return false;
        }
   
    
}

function changehomepageStatus(id)
{
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");

	$.ajax({
        type: "POST",
        data: ({id: id}),
        url: "/admin/homepage/changehomepageStatus/",
        success: function(data){
            $("#loader").hide();
            window.location.reload();
        }
    });
}

function deleteBlogs(id)
{
    if(confirm("Are you sure that you want to delete this post?"))
    {
         location.href="/admin/blog/delete/id/"+id;
    }
    else{
        return false;
    }
}

function changeBlogStatus(id)
{
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");

	$.ajax({
        type: "POST",
        data: ({id: id}),
        url: "/admin/blog/changestatus/",
        success: function(data){
            $("#loader").hide();
            window.location.reload();
        }
    });
}

function getHomepageSubSection()
{
	var sectid = $("#section").val();
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");

	$.ajax({
        type: "POST",
        data: ({sectid: sectid}),
        url: "/admin/homepage/getsubsection/",
        success: function(data){
            $("#loader").hide();
            //window.location.reload();
            $("#subsection").html(data);
        }
    });
}